home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / p2c1.20-a5.appl Folder / p2c 1.20a5 / doc / p2c.man.text < prev    next >
Encoding:
Text File  |  1992-11-25  |  44.8 KB  |  763 lines  |  [TEXT/nX^n]

  1.  
  2. NAME     
  3.         p2c - Pascal to C translator, version 1.20 
  4. SYNOPSIS     
  5.         p2c [ options ] [ file [ module ] ] 
  6.  
  7. DESCRIPTION 
  8. P2c is a tool for translating Pascal programs into C. The input consists of a set of source files in 
  9. any of the following Pascal dialects: HP Pascal, Turbo/UCSD Pascal, DEC VAX Pascal, 
  10. Oregon Software Pascal/2, Macintosh Programmer's Workshop Pascal, Sun/Berkeley Pascal. 
  11. Modula-2 syntax is also supported. Output is a set of .c and .h files that comprise an equivalent 
  12. program in any of several dialects of C. Output code may be kept machine- and dialect-
  13. independent, or it may be targeted to a specific machine and compiler. Most reasonable Pascal 
  14. programs are converted into fully functional C which will compile and run with no further 
  15. modifications, although p2c sometimes chooses to generate readable code at the expense of 
  16. absolute generality. 
  17.  
  18. P2c endeavors to insert notes and warning messages into the output code to point out areas 
  19. which may require human intervention. Output code is arranged to be readable and efficient, and 
  20. to make use of C idioms wherever possible. The main goal of the translation is to produce C 
  21. files which are pleasant and "natural" enough to be acceptable as the new source files for a 
  22. program. In a pinch, p2c will also serve as an ad hoc Pascal compiler.
  23.  
  24. Code generated by p2c normally does not assume characters are signed or unsigned. Also, it 
  25. assumes int is the same as either short or long but does not depend on which. However, if int is 
  26. not the same as long it is best to use a modern C compiler which supports prototypes. Generated 
  27. code does not require an ANSI-compatible compiler (unless ANSI-style code is requested), but 
  28. it does use various ANSI-standard library routines.
  29.  
  30. All generated code includes the file <p2c.h> which in turn includes <stdio.h> and various other 
  31. common resources. Also, many translated programs will need to be linked with the run-time 
  32. library, typically -lp2c.
  33.  
  34. Given a file name, p2c reads from the specified file and outputs to a file with a .c suffix added or 
  35. substituted. For example, 
  36.     p2c myfile.p
  37.  
  38. reads from myfile.p to produce the file myfile.c. The input file may contain a Pascal main 
  39. program or a single Pascal module (or "unit" in UCSD Pascal nomenclature), or it may just 
  40. contain a number of procedures and declarations. P2c is designed to work for correct input 
  41. programs. That is, it will accept partial programs but may occasionally crash if the input refers to 
  42. undefined symbols.
  43.  
  44. If the input is a module, the translator will also produce a file module .h containing a translation 
  45. of the module's interface section. The implementation section may be omitted in which case only 
  46. the .h file will be interesting. If the program or module has include files, these may cause 
  47. additional .c files to be generated depending on the value of the ExpandIncludes option (see 
  48. below).
  49.  
  50. If no file name is given, p2c reads Pascal from the standard input and writes the resulting C to 
  51. standard output (though a .h file may still be produced). If a file name and module name are 
  52. given, the file may include several modules (or units). The specified module is translated; any 
  53. others are skipped. The output files will be named module .c and module .h . P2c never 
  54. translates more than one module per run.
  55.  
  56. The input program or module may make use other modules. These modules may be referred to 
  57. explicitely.  P2c holds a search list of places to find modules which are imported, the ImportDir 
  58. search list. Modules for inlusion may as well reside in additional default input files which are 
  59. imported before beginning the translation.
  60.  
  61. When starting, p2c a number of configuration parameters are set. The default parameters are 
  62. stored in p2c’s resource fork as resource of type 'p2c  '. These default parameters can be modi
  63. fied using ResEdit. Next the file "p2c preferences" is read for a number of configuration para
  64. meters from the preferences folder. (The actual path used on your system may vary. The -i 
  65. option is a handy way to examine this file.) If the P2CRC environment variable is set, it gives 
  66. the name of a file to read instead of the system file; this file can start with Include 
  67. %H/"p2c preferences" to include the system file. Next, p2c attempts to read the file 
  68. “p2c preferences” in your input directory for further configuration.
  69.  
  70. OPTIONS
  71.  
  72. -o cfile    Use cfile in place of file .c or module .c as the primary output file. A single dash 
  73. ('–o –') says to write the C code to the standard output.
  74.  
  75. -h hfile    Use hfile in place of module .h as the output file for interface text. This only has 
  76. effect if the input is an HP Pascal module or a Pascal unit.
  77.  
  78. -s sfile     Read interface text from sfile before beginning the translation. This file typically 
  79. contains one or more modules, often with implementation sections omitted for 
  80. speed, which the program or module being translated will use. (Typically the 
  81. ImportFrom and ImportDir parameters in p2crc are set up to allow p2c to locate 
  82. interface text without needing any -s options.) If there are several -s options in the 
  83. command, the sfiles are read from left to right.
  84.  
  85. -p n    Display progress of translation in the form of a line number/file name display. This 
  86. is refreshed every n lines, 25 by default.
  87.  
  88. -c prefsfile    Read local configuration commands from prefsfile instead of "p2c preferences".  A 
  89. dash ('–c –') in place of prefsfile causes no local configuration file to be used.
  90.  
  91.  -v    ("Vanilla.") Do not read from the system configuration file "p2c preferences". Since 
  92. some of the parameters in this file are required, the p2c resource must include those 
  93. parameters instead. This also suppresses the file named by the P2CRC environment 
  94. variable.
  95.  
  96. -H homedir    Use homedir as the p2c home directory. The system "p2c preferences" file will be 
  97. searched for in this directory. 
  98.  
  99. -I pattern    Add pattern to the ImportDir search list of places to find modules which are 
  100. imported. The pattern should include a %s to represent the module name, and 
  101. should evaluate to a potential file name for that module's source code. For example, 
  102. ::%s.p looks for <modulename>.p in the parent of the current directory.
  103.  
  104.  -i    This special option copies the p2c system configuration to the standard output in its 
  105. entirety. (It may be used with -H , but -i is most useful precisely when you don't 
  106. know the location of the home directory.)
  107.  
  108.  -q    Quiet mode. Suppresses output of status messages during translation.
  109.  
  110. -E n    Abort translation after n errors. If n is omitted it defaults to zero, which means 
  111. unlimited errors are allowed. Use -E 1 to make p2c halt after the first error.
  112.  
  113.  -e    Echo the Pascal source into the output file, surrounded by #ifdefs. This is the same 
  114. as the CopySource parameter in the "p2c preferences" file.
  115.  
  116.  -a    Produce modern ANSI C. This is a convenient override for the AnsiC parameter in 
  117. the "p2c preferences" file.
  118.  
  119. -L language    Select input language name, such as MPW, VAX or TURBO. This is a convenient 
  120. override for the Language parameter.
  121.  
  122.  -V    Verbose mode. This causes p2c to generate an additional ".log" file with further 
  123. details of the translation, such as a list of warnings and notes including those which 
  124. are suppressed in the regular output.
  125.  
  126.  -M0    Disable memory conservation. This prevents p2c from freeing various data 
  127. structures after translating each function, in case this new conservation feature 
  128. causes unforseen problems.
  129.  
  130.  -R    Regression testing mode. Formats notes and warning messages in a way that makes 
  131. it easier to run compare on the output of p2c.
  132.  
  133. P2c also understands a few debugging options which may occasionally be useful when tracking 
  134. down translation problems. The -d n option sets the "debug level" to n, a small integer which is 
  135. normally zero. Debugging output is written into the regular output file along with the C code; the 
  136. higher your n, the more "wallpaper" you get. Also, -t prints debugging information at every 
  137. Pascal token, -B n enables line-breaker debugging, and -C n enables comment placement 
  138. debugging.
  139.  
  140. CHOICE OF SOURCE LANGUAGE 
  141. The Language configuration parameter or -L command-line option tells p2c which Pascal dialect 
  142. to expect in the input file. Any language features which do not overlap between dialects are 
  143. supported all of the time. The Language parameter is consulted when a syntax or usage is 
  144. detected that has different meanings in two different dialects, and also to determine default 
  145. values for various other translation parameters as described below.
  146.  
  147. The following language words are supported by p2c. Names are case-insensitive.
  148.  HP    HP Pascal. All features of HP Standard Pascal, the Pascal Workstation version, are 
  149. supported except as noted in BUGS below. Some features of MODCAL, HP's 
  150. extended Pascal, are also supported. This is a superset of ISO standard Pascal, 
  151. including conformant arrays and procedural parameters.
  152.  
  153.  HP-UX     HP Pascal, HP-UX version. Almost identical to the "HP" dialect.
  154.  
  155.  Turbo     Turbo Pascal 5.0 for the IBM PC. Few conflicts with HP Pascal, so the Language 
  156. parameter is not often needed for Turbo. (Most important is that the Turbo and HP 
  157. dialects use 16 and 32 bit integers, respectively.)
  158.  
  159.  UCSD     UCSD Pascal. Similar to Turbo in many ways.
  160.  
  161.  MPW     Macintosh Programmer's Workshop Pascal 2.0. This is the default language. 
  162. Should also do a pretty good job for Think Pascal. Object Pascal features are not 
  163. supported, nor is the fact that char variables are sometimes stored in 16 bits.
  164.  
  165.  VAX     VAX/VMS Pascal version 3.5. Most but not all language features supported. This 
  166. has not yet been tested on large programs.
  167.  
  168.  Oregon     Oregon Software Pascal/2. All features implemented.
  169.  
  170.  Berk     Berkeley Pascal with Sun extensions.
  171.  
  172.  Modula     Modula-2. Based on Wirth's Programming in Modula-2, 3rd edition. Proper setting 
  173. of the Language parameter is not optional. Translation will be incomplete in most 
  174. cases, but should be good enough to work with. Structure of local sub-modules is 
  175. essentially ignored; like-named identifiers may be confused. Type WORD is 
  176. translated as an integer, but type ADDRESS is translated as char * or void *; this 
  177. may cause inconsistencies in the output code.
  178.  
  179.     Modula-2 modules have two parts in separate files. Suppose these are called 
  180. foo.def (definition part) and foo.mod (implementation part) for module foo. Then a 
  181. pattern like %s.def must be included in the ImportDir list, and LibraryFile must be 
  182. changed to refer to system.m2 instead of system.imp. To translate the definition 
  183. part, give the command
  184.          p2c foo.def
  185.     to translate the definition part into files foo.h and foo.c ; the latter will usually be 
  186. empty. The command
  187.         p2c -s foo.def foo.mod
  188.     will translate the implementation part into file foo.c.
  189.  
  190. Even if all language features are supported for a dialect, some predefined functions may be 
  191. omitted. In these cases, the function call will be translated literally into C with a warning. Some 
  192. hand modification may be required. 
  193.  
  194. CONFIGURATION PARAMETERS 
  195. P2c is highly configurable. The defaults are suitable for most applications, but customizing these 
  196. parameters will help you get the best possible translation. Since the output of p2c is intended to 
  197. be used as human-maintainable source code, there are many parameters for describing the 
  198. coding style and conventions you prefer. Others give hints about your program that help p2c to 
  199. generate more correct, efficient, or readable code.
  200.  
  201. The p2crc files contain a list of parameters, one per line. The system configuration file, which 
  202. may be viewed using the -i option to p2c, serves as an example of the proper format. Parameter 
  203. names are case-insensitive. If a parameter name occurs exactly once in the system p2crc, this 
  204. indicates that it must have a unique value and the last value given to it by the configuration files 
  205. is used. Other parameters are written several times in a row; these are lists to which each 
  206. configuration line adds an entry.
  207.  
  208. Many p2crc options take a numeric value of 0 or 1, roughly corresponding to "no" or "yes." 
  209. Sometimes a blank value or the value "def" corresponds to an intermediate "maybe" state. For 
  210. example, the stylistic option ExtraParens switches between copious or minimal parentheses in 
  211. expressions, with the default being a nice compromise intended to be best for readers with an 
  212. average knowledge of C operator precedences.
  213.  
  214. Configuration options may also be embedded in the source file in the form of Pascal comments:
  215.  
  216.     {ShortOpt=0} {AvoidName=fred}
  217.     {FuncMacro slope(x,y)=atan2(y,x)*RadDeg}
  218.  
  219. disables automatic short-circuiting of and and or expressions, adds "fred" to the list of names to 
  220. avoid using in generated C code, and defines a special translation for the Pascal program's slope 
  221. function using the standard C atan2 function and a constant RadDeg presumably defined in the 
  222. program. Whitespace is generally not allowed in embedded parameters. The `=' sign is required 
  223. for embedded parameters, though it is optional in p2crc files. Comments within embedded 
  224. parameters are delimited by `##'. Numeric parameters may replace `=' with `+' or `-' to increase 
  225. or decrease the parameter; list-based parameters may use `-' to remove a name from a list rather 
  226. than adding it. Also, the parameter name by itself in comment braces means to restore the 
  227. parameter's value that was current before the last change:
  228.  
  229.     {VarFiles=0 ## Pass FILE *'s params by value even if VAR}    some declarations
  230.     {VarFiles  ## Back to original FILE * passing}
  231.  
  232. causes the parameter VarFiles to have the value 0 for those few declarations, without affecting 
  233. the parameter's value elsewhere in the file.
  234.  
  235. If an embedded parameter appears in an include file or in interface text for a module, the effect of 
  236. the assignment normally carries over to any programs that included that file. If the parameter 
  237. name is preceded by a `*', then the assignment is automatically undone after the source file that 
  238. contains it ends:
  239.  
  240.     {IncludeFrom strings=<p2c/strings.h>}
  241.     {*ExportSymbol=pascal_%s}
  242.     module strings;
  243.  
  244. will record the location of the strings module's include file for the rest of the translation, but the 
  245. assignment of ExportSymbol pertains only to the module itself.
  246.  
  247. For the complete list of p2crc parameters, run p2c with the -i option. Here are some additional 
  248. comments on selected parameters:
  249.  
  250. ImportAll
  251. Because Turbo Pascal only allows one unit per source file, p2c normally stops reading past 
  252. the word implementation in a file being scanned for interface text. But HP Pascal allows 
  253. several modules per file and so this would not be safe to do. The ImportAll option lets you 
  254. override the default behavior for your Pascal dialect.
  255.  
  256. AnsiC
  257. This parameter selects which dialect of C to use. If 1, all conventions of ANSI C such as 
  258. prototypes, void * pointers, etc. are used. If 0, only strict K&R (first edition) C is used. The 
  259. default is to use "traditional UNIX C," which includes enum and void but not void * or 
  260. prototypes. Once again there are a number of other parameters which may be used to control 
  261. the individual features if just setting AnsiC is not enough.
  262.  
  263. C++
  264. At present p2c does not use much of C++ at all. The default action is to generate code that 
  265. will compile in either language.
  266.  
  267. UseVExtern
  268. Many non-UNIX linkers prohibit variables from being defined (not declared) by more than 
  269. one source file. One module must declare, e.g., "int foo;", and all others must declare 
  270. "extern int foo;". P2c accomplishes this by declaring public variables "vextern" in header 
  271. files, and arranging for the macro vextern to expand to extern or to nothing when 
  272. appropriate. If you set UseVExtern =0 p2c will instead declare variables in a simpler way 
  273. that works only on UNIX-style linkers.
  274.  
  275. UseAnyptrMacros
  276. Certain C reserved words have meanings which may vary from one C implementation to 
  277. another. P2c uses special capitalized names for these words; these names are defined as 
  278. macros in the file p2c.h which all translated programs include. You can set 
  279. UseAnyptrMacros = 0 to disable the use of these macros. Note that the functions of many 
  280. of these macros can also be had directly using other parameters; for example, UseConsts 
  281. allows you to specify whether your target language recognizes the word const in constant 
  282. declarations. The default is to use the Const macro instead, so that your code will be portable 
  283. to either kind of implementation.
  284.  
  285. Signed expands to the reserved word signed if that word is available, otherwise it is given a 
  286. null definition. Similarly, Const expands to const if that feature is available. The words 
  287. Volatile and Register are also defined in p2c.h, although p2c does not use them at present. 
  288. The word Char expands to char by default, but might need to be redefined to signed char or 
  289. unsigned char in a particular implementation. This is used for the Pascal character type; 
  290. lowercase char is used when the desired meaning is "byte," not "character."
  291.  
  292. The word Static always expands to static by default. This is used in situations where a 
  293. function or variable is declared static to make it local to the source file; lowercase static is 
  294. used for static local variables. Thus you can redefine Static to be null if you want to force 
  295. private names to be public for purposes of debugging.
  296.  
  297. The word Void expands to void in all cases; it is used when declaring a function with no 
  298. return value. The word Anyptr is a typedef for void * or char * as necessary; it represents a 
  299. generic pointer.
  300.  
  301. UsePPMacros
  302.  
  303. The p2c.h header also declares two macros for function prototyping, PP (x) and PV (). 
  304. These macros are used as follows:
  305.  
  306.         Void foo PP( (int x, int y, Char *z) );
  307.         Char *bar PV( );
  308.  
  309. If prototypes are available, these macros will expand to
  310.  
  311.         Void foo (int x, int y, Char *z);
  312.         Char *bar (void);
  313.  
  314. but if only old-style declarations are supported, you instead get
  315.  
  316.         Void foo ();
  317.         Char *bar ();
  318.  
  319. By default, p2c uses these macros for all function declarations, but function definitions are 
  320. written in old-style C. The UsePPMacros parameter can be set to 0 to disable all use of PP 
  321. and PV , or it can be set to 1 to use the macros even when defining a function. (This is 
  322. accomplished by preceding each old-style definition with a PP -style declaration.) If you 
  323. know your code will always be compiled on systems that support prototyping, it is prettier 
  324. to set Prototypes =1 or simply AnsiC =1 to get true function prototypes.
  325.  
  326. EatNotes
  327.  
  328. Notes and warning messages containing any of these strings as sub-strings are not omitted. 
  329. Each type of message includes an identifier like [145] ; you can add this identifier to the 
  330. EatNotes list to suppress that message. Another useful form is to use a variable name or 
  331. other identifier to suppress warnings about that variable. The strings are a space-separated 
  332. list, and thus may not contain embedded spaces. To suppress notes around a section of 
  333. code, use, e.g., {EatNotes+[145]} and {EatNotes-[145]}. Most notes are generated during 
  334. parsing, but to suppress those generated during output the string may need to remain in the 
  335. list far beyond the point where it appears to be generated. Use the string "1" or "0" to disable 
  336. or enable all notes, respectively.
  337.  
  338. ExpandIncludes
  339. The default action is to expand Pascal include files in-line. This may not be desirable if 
  340. include files are being used to simulate modules. With ExpandIncludes =0, p2c attempts to 
  341. convert include files containing only whole procedures and global declarations into 
  342. analogous C include files. This may not always work, though; if you get error messages, 
  343. don't use this option. By combining this option with StaticFunctions =0, then doing some 
  344. fairly minor editing on the result, you can convert a pseudo-modular Pascal program into a 
  345. truly modular collection of C source files.
  346.  
  347. ElimDeadCode
  348. Some transformations that p2c does on the program may result in unreachable or "dead" 
  349. code. By default p2c removes such code, but sometimes it removes more than it should. If 
  350. you have "if false" segments which you wish to retain in C, you may have to set 
  351. ElimDeadCode =0.
  352.  
  353. SkipIndices
  354. Normally Pascal arrays not based at zero are "shifted" down for C, preserving the total size 
  355. of the array. A Pascal array a[2..10] is translated to a C array a[9] with references like "a[i]" 
  356. changed to "a[i-2]" everywhere. If SkipIndices is set to a value of 2 or higher, this array 
  357. would instead be translated to a[11] with the first two elements never used. This 
  358. arrangement may generate incorrect code, though, for tricky source programs.
  359.  
  360. FoldConstants
  361. Pascal non-structured constants generally translate to #define 's in C. Set this to 1 to have 
  362. constants instantiated directly into the code. This may be turned on or off around specific 
  363. constant declarations. Set this to 0 to force p2c to make absolutely no assumptions about the 
  364. constant's value in generated code, so that you can change the constant later in the C code 
  365. without invalidating the translation. The default is to allow p2c to take advantage of its 
  366. knowledge of a constant's value, such as by generating code that assumes the constant is 
  367. positive.
  368.  
  369. CharConsts
  370. This governs whether single-character string literals in Pascal const declarations should be 
  371. interpreted as characters or strings. In other words, const a='x'; will translate to #define a 
  372. 'x' if CharConsts =1 (the default), or to #define a "x" if CharConsts =0. Note that if p2c 
  373. guesses wrong, the generated code will not be wrong, just uglier. For example, if a is 
  374. written as a character constant but it turns out to be used as a string, p2c will have to write 
  375. char-to-string conversion code each time the constant is used.
  376.  
  377. VarStrings
  378. In HP Pascal, a parameter of the form "var s : string" will match a string variable of any size; 
  379. a hidden size parameter is passed which may be accessed by the Pascal strmax function. You 
  380. can prevent p2c from creating a hidden size parameter by setting VarString =0. (Note that 
  381. each function uses the value of VarStrings as of the first declaration of the function that is 
  382. parsed, which is often in the interface section of a module.)
  383.  
  384. Prototypes
  385. Control whether ANSI C function prototypes are used. Default is according to AnsiC . This 
  386. also controls whether to include parameter names or just their types in situations where 
  387. names are optional. The FullPrototyping parameter allows prototypes to be generated for 
  388. declarations but not for definitions (older versions of Lightspeed C required this). If you use 
  389. a mixture of prototypes and old-style definitions, types like short and float will be promoted 
  390. to int and double as required by the ANSI standard, unless PromoteArgs is used to override 
  391. this. The CastArgs parameter controls whether type-casts are used in function arguments; 
  392. by default they are used only if prototypes are not available.
  393.  
  394. StaticLinks
  395. HP Pascal and Turbo Pascal each include the concept of procedure or function pointers, 
  396. though with somewhat different syntaxes. P2c recognizes both notational styles. Another 
  397. difference is that HP's procedure pointers can point to nested procedures, while Turbo's can 
  398. point only to global procedures. In HP Pascal a procedure pointer must be stored as a struct 
  399. containing both a pure C function pointer and a "static link," a pointer to the parent 
  400. procedure's locals. (The static link is NULL for global procedures.) This notation can be 
  401. forced by setting StaticLinks =1. In Turbo, the default ( StaticLinks =0) is to use plain C 
  402. function pointers with no static links. A third option ( StaticLinks =2) uses structures with 
  403. static links, but assumes the links are always NULL when calling through a pointer (if you 
  404. need compatibility with the HP format but know your procedures are global).
  405.  
  406. SmallSetConst
  407. Pascal sets are translated into one of two formats, depending on the size of the set. If all 
  408. elements have ordinal values in the range 0..31, the set is translated as a single integer 
  409. variable using bit operations. (The SetBits parameter may be used to change the upper limit 
  410. of 31.) The SmallSetConst parameter controls whether these small-sets are used, and, if so, 
  411. how constant sets should be represented in C. For larger sets, an array of long is used. The 
  412. s [0] element contains the number of succeeding array elements which are in use. Set 
  413. elements in the range 0..31 are stored in the s [1] array element, and so on. Sets are 
  414. normalized so that s [ s [0]] is nonzero for any nonempty set. The standard run-time library 
  415. includes all the necessary procedures for operating on sets.
  416.  
  417. ReturnValueName
  418. This is one of many "naming conventions" parameters. Most of these take the form of a 
  419. printf -like string containing a %s where the relevant information should go. In the case of 
  420. ReturnValueName , the %s refers to a function name and the resulting string gives the name 
  421. of the variable to use to hold the function's return value. Such a variable will be made if a 
  422. function contains assignments to its return value buried within the body, so that return 
  423. statements cannot conveniently be used. Some parameters ( ReturnValueName included) do 
  424. not require the %s to be present in the format string; for example, the standard p2crc file 
  425. stores every function's return value in a variable called Result.
  426.  
  427. AlternateName
  428. P2c normally translates Pascal names into C names verbatim, but occasionally this is not 
  429. possible. A Pascal name may be a C reserved word or traditional C name like putc, or there 
  430. may be several like-named things that are hidden from each other by Pascal's scoping rules 
  431. but must be global in C. In these situations p2c uses the parameter AlternateName1 to 
  432. generate an alternative name for the symbol. The default is to add an underscore to the name. 
  433. There is also an AlternateName2 parameter for a second alternate name, and an 
  434. AlternateNamen parameter for the n th alternate name. (The value for this parameter should 
  435. include both a %s and a %d, in either order.) If these latter parameters are not defined, p2c 
  436. applies AlternateName1 many times over.
  437.  
  438. ExportSymbol
  439. Symbols in the interface section for a Pascal module are formatted according to the value of 
  440. ExportSymbol , if any. It is not uncommon to use modulename_%s for this symbol; the 
  441. default is %s, i.e., no special treatment for exported symbols. If you also define the 
  442. Export_Symbol parameter, that format is used instead for exported symbols which contain 
  443. an underscore character. If %S (with a capital "S") appears in the format string it stands for 
  444. the current module name.
  445.  
  446. Alias
  447. If the value of this parameter contains a %s, it is a format string applied to the names of 
  448. external functions or variables. If the value does not contain a %s, it becomes the name of 
  449. the next external symbol which is declared (after which the parameter is cleared).
  450.  
  451. Synonym
  452. This creates a synonym for another Pascal symbol or keyword. The format is
  453.  
  454.     Synonym old-name = new-name
  455.  
  456. All occurrences of old-name in the input text are treated as if they were new-name by the 
  457. parser. If new-name is a keyword, old-name will be an equivalent keyword. If new-name is 
  458. the name of a predefined function, old-name will behave in the same way as that function, 
  459. and so on. If new-name is omitted, then occurrences of old-name are entirely ignored in the 
  460. input file. Synonyms allow you to skip over a keyword in your dialect of Pascal that is not 
  461. understood by p2c, or to simulate a keyword or predefined identifier of your dialect with a 
  462. similar one that p2c recognizes. Note that all predefined functions are available at all times; if 
  463. you have a library routine that behaves like, e.g., Turbo Pascal's getmem procedure, you 
  464. can make your routine a synonym for getmem even if you are not translating in Turbo mode.
  465.  
  466. NameOf
  467. This defines the name to use in C for a specific symbol. It must appear before the symbol is 
  468. declared in the Pascal code; it is usually placed in the local p2crc file for the project. The 
  469. format is
  470.  
  471.     NameOf pascal-name = C-name
  472.  
  473. By default, Pascal names map directly onto C names with no change (except for the various 
  474. kinds of formatting outlined above). If the pascal-name is of the form module.name or 
  475. procedure.name then the command applies only to the instance of the Pascal name that is 
  476. global to that module, or local to that procedure. Otherwise, it applies to all usages of the 
  477. name.
  478.  
  479. VarMacro
  480. This is analogous to NameOf , but specifically for use with Pascal variables. The righthand 
  481. side can be most any C expression; all references to the variable are expanded into that C 
  482. expression. Names used in the C expression are taken verbatim. There is also a 
  483. ConstMacro parameter for translating constants as arbitrary expressions. Note that the 
  484. variable on the lefthand side must actually be declared in the program or in a module that it 
  485. uses. The declaration for the variable will be omitted from the generated code unless the 
  486. Pascal-name appears in the expression: If you ask to replace i with i+1, the variable i will 
  487. still be declared but its value will be shifted accordingly. Note that if i appears on the 
  488. lefthand side of an assignment, p2c will use algebra to "solve" for i.
  489.  
  490. In all cases where p2c parses C expressions, all C operators are recognized except 
  491. compound assignments like `+='. (Increment and decrement operators are allowed.) All 
  492. variable and function names are assumed to have integer type, even if they are names that 
  493. occur in the actual program. A type-specification operator `::' has been introduced; it has the 
  494. same precedence as `.' or `->' but the righthand side must be a Pascal type identifier (built-in 
  495. or defined by your program previously to when the macro definition was parsed), or an 
  496. arbitrary Pascal type expression in parentheses. The lefthand argument is then considered to 
  497. have the specified type. This may be necessary if your macro is used in situations where the 
  498. exact type of the expression must be known (say, as the argument to a writeln ).
  499.  
  500. FieldMacro
  501. Here the lefthand side must have the form record.field, where record is the Pascal type or 
  502. variable name for a record, and field is a field in that record. The righthand side must be a C 
  503. expression generally including the name record. All instances of that name are replaced by 
  504. the actual record being "dotted." For example,
  505.  
  506.     FieldMacro Rect.topLeft = topLeft(Rect)
  507.  
  508. translates a[i].topLeft into topLeft(a[i]), where a is an array of Rect.
  509.  
  510. FuncMacro
  511. The lefthand side must be any Pascal function or procedure name plus a parameter list. The 
  512. number of parameters must match the number in the function's uses and declaration. Calls to 
  513. the function are replaced by the C expression on the righthand side. For example,
  514.  
  515.     FuncMacro PtInRect(p,r) = PtInRect(p,&r)
  516.  
  517. causes the second argument of PtInRect to be passed by reference, even though the 
  518. declaration says it's not. If the function in question is actually defined in the program or 
  519. module being translated, the FuncMacro will not affect the definition but it will affect all 
  520. calls to the function elsewhere in the module. FuncMacros can also be applied to predefined 
  521. or never-defined functions.
  522.  
  523. IncludeFrom
  524. This specifies that a given module's header should be included from a given place. The 
  525. second argument may be surrounded by " " or < > as necessary; if the second argument is 
  526. omitted, no include directive will be generated for the module.
  527.  
  528. ImportFrom
  529. This specifies that a given module's Pascal interface text can be found in the given file. The 
  530. named file should be either the source file for the module, or a specially prepared file with 
  531. the implementation section removed for speed. If no ImportFrom entry is found for a 
  532. module, the path defined by the ImportDir list is searched. Each entry in the path may 
  533. contain a %s, which expands to the name of the module. The default path looks for %s.pas 
  534. and %s.text in the current directory, then for --HOMEDIR--/%s.imp. (where --HOMEDIR-- 
  535. is the p2c home directory.)
  536.  
  537. StructFunction
  538. This parameter is a list of functions which follow the p2c semantics for structure-valued 
  539. functions (functions returning arrays, sets, and strings, and structs in primitive C dialects). 
  540. For these functions, a pointer to a return-value area is passed to the function as a special first 
  541. parameter. The function stores the result in this area, then returns a copy of the pointer. (The 
  542. standard C function strcpy is an example of this concept. Sprintf also behaves this way in 
  543. some dialects; it always appears on the StructFunction list regardless of the type of 
  544. implementation.) The system configuration file includes a list of common structured 
  545. functions so that p2c 's optimizer will know how to manipulate them.
  546.  
  547. StrlapFunction
  548. Functions on this list are structured functions as above, but with the ability to work in-place; 
  549. that is, the same pointer may be passed as both the return value area and a regular parameter.
  550.  
  551. Deterministic Functions on this list have no side effects or side dependencies. An example is 
  552. the sin function in the standard math library; two calls with the same parameter values 
  553. produce the same result, and have no effects other than returning a value. P2c can make use 
  554. of this knowledge when optimizing code for efficiency or readability. Functions on this list 
  555. are also assumed to be relatively fast, so that it is acceptable to duplicate a call to the 
  556. function.
  557.  
  558. LeaveAlone Functions on this list are not subjected to the normal built-in translation rules 
  559. that p2c would otherwise use. For example, adding writeln to this list would translate 
  560. writeln statements blindly into calls to a C writeln() function, rather than being translated into 
  561. equivalent printf calls. The built-in translation is also suppressed if the function has a 
  562. FuncMacro .
  563.  
  564. BufferedFile
  565. P2c normally assumes binary files will use read/write, not get/put/^ notation. A file buffer 
  566. variable will only be created for a file if buffer notation is used for it. For global file 
  567. variables this may be detected too late (a declaration without buffers may already have been 
  568. written). Such files can be listed in BufferedFile to force p2c to allocate buffers for them; do 
  569. this if you get a warning message that says it is necessary. Set BufferedFile =1 to buffer all 
  570. files, in which case UnBufferedFile allows you to force certain files not to have buffers.
  571.  
  572. StructFiles
  573. If p2c still can't translate your file operations correctly, you can set StructFiles =1 to cause 
  574. Pascal files to translate into structs which include the usual C FILE pointer, as well as file 
  575. buffer and file name fields. While the resulting code doesn't look as much like native C, the 
  576. file structs will allow p2c to do a correct translation in many more cases.
  577.  
  578. CheckFileEOF
  579. Normally only file-open operations are checked for errors. Additional error checking, such 
  580. as read-past-end-of-file, can be enabled with parameters like CheckFileEOF . These checks 
  581. can make the code very ugly! If I/O checking is enabled by the program ( "$iocheck on$" in 
  582. HP Pascal; {$I+} in Turbo; this is always the default state), these checks will generate fatal 
  583. errors unless enclosed in an HP Pascal try - recover construct. If I/O checking is disabled, 
  584. these will cause the global variable P_ioresult to be set zero or nonzero according to the 
  585. outcome. The default for most of these options is to check only when I/O checking is 
  586. disabled. 
  587.  
  588.  
  589. ISSUES
  590.  
  591. Integer size.
  592. P2c normally generates code to work with either 16 or 32 bit ints. If you know your C integers 
  593. will be 16 or 32 bits, set IntSize appropriately. In particular setting IntSize =32 will generate 
  594. much cleaner code: p2c no longer must carefully cast function arguments between int and long. 
  595. These casts also will be unnecessary if ANSI prototypes are available. To disable int/long 
  596. casting because you know at least one of these cases will hold, set CastLongArgs =0. (The 
  597. CastArgs parameter similarly controls other types of casts, such as between ints and doubles.) 
  598. The Integer16 parameter controls whether Pascal integers are interpreted as 16 or 32 bits, or 
  599. translated as native C integers. The default value depends on the Language selected.
  600.  
  601. Signed/unsigned chars.
  602. Pascal characters are normally "weakly" interpreted as unsigned; this is controlled by 
  603. UnsignedChar . The default is "either," so that C's native char type may be used even if its 
  604. signed-ness is unknown. Code that uses characters outside of the range 0-127 may need a 
  605. different setting. Alternatively, you can use the types {SIGNED} char and {UNSIGNED} char 
  606. in the few cases where it really matters. These comments are controlled by the SignedComment 
  607. and UnsignedComment parameters. (The type {UNSIGNED} integer is also recognized.) The 
  608. SignedChar parameter tells whether C characters are signed or unsigned (default is 
  609. "unknown"). The HasSignedChar parameter tells whether the phrase "signed char" is legal in 
  610. the output. If it is not, p2c may have to translate Pascal signed bytes into C shorts.
  611.  
  612. Special types.
  613. P2c understands the following predefined Pascal type names: 
  614.     integer    signed integers depending on Integer16 ; 
  615.     longint    signed 32-bit integers; 
  616.     unsigned    unsigned 32-bit integers; 
  617.     sword    signed 16-bit integers; 
  618.     word    unsigned 16-bit integers; 
  619.     c_int    signed native C integers; 
  620.     c_uint    unsigned native C integers; 
  621.     sbyte    signed 8-bit integers; 
  622.     byte    unsigned 8-bit integers; 
  623.     real    floating-point numbers depending on DoubleReals ;     
  624.     single    single-precision floats; 
  625.     longreal , 
  626.     double , 
  627. and    extended    double-precision floats;     
  628.     pointer 
  629. and    anyptr    generic pointers (assignment-compatible with any pointer type); 
  630.     string    generic string of length StringDefault (normally 255); 
  631. also, the usual Pascal types 
  632.     char
  633.     boolean,
  634. and 
  635.     text . 
  636. (If your Pascal uses different names for these concepts, the Synonym option will come in 
  637. handy.)
  638.  
  639. Embedded code. 
  640. It is possible to write a Pascal comment containing C code to be embedded into the output. See 
  641. the descriptions of EmbedComment and its relatives in the system p2crc file. These techniques 
  642. are helpful if you plan to do repeated translations of code that is still being maintained in Pascal.
  643.  
  644. Comments and blank lines. 
  645. P2c collects the comments in a procedure into a list. All comments and statements are stamped 
  646. with serial numbers which are used to reattach comments to statements even after code has been 
  647. added, removed, or rearranged during translation. "Orphan" comments attached to statements 
  648. that have been lost are attached to nearby statements or emitted at the end of the procedure. 
  649. Blank lines are treated as a kind of comment, so p2c will also reproduce your usage of blank 
  650. lines. If the comment mechanism goes awry, you can disable comments with EatComments or 
  651. disable their being attached to code with SpitComments .
  652.  
  653. Indentation. 
  654. P2c has a number of parameters to govern indentation of code. The default values produce the 
  655. GNU Emacs standard indentation style, although p2c can do a better job since it knows more 
  656. about the code it is indenting. Indentation works by applying "indentation deltas," which are 
  657. either absolute numbers (which override the previous indentation), or signed relative numbers 
  658. (which augment the previous indentation). A delta of "+0" specifies no change in indentation. 
  659. All of the indentation options are described in the standard p2crc file.
  660.  
  661. Line breaking. 
  662. P2c uses an algorithm similar to the TeX typesetter's paragraph formatter for breaking long 
  663. statements into multiple lines. A "penalty" is assigned to various undesirable aspects of all 
  664. possible line breaks; the "badness" of a set of line breaks is approximately the sum of all the 
  665. penalties. Chief among these are serious penalties for overrunning the desired maximum line 
  666. length (default 78 columns), an infinite penalty for overrunning the absolute maximum line 
  667. length (default 90), and progressively greater penalties for breaking at operators deeply nested in 
  668. expressions. Parameters such as OpBreakPenalty control the relative weights of various 
  669. choices. BreakArith and its neighbors control whether the operator at a line break should be 
  670. placed at the end of the previous line or at the beginning of the next. If you don't want any 
  671. oversize lines, define MaxLineWidth =78.
  672.  
  673. Unlike TeX, p2c 's line breaker must actually try all possible sets of break points. To avoid 
  674. excessive computation, the total penalty contributed at each decision point must sum to a 
  675. nonnegative value; negative values are clipped up to zero. This allows p2c to prune away 
  676. obviously undesirable alternatives in advance. The MaxLineBreakTries parameter (default 
  677. 5000) controls how many alternatives to try before giving up and using the best so far.
  678.  
  679. PASCAL_MAIN. 
  680. P2c generates a call to this function at the front of the main program. In the (unmodified) run-
  681. time library all this does is save argc and argv away because in both HP and Turbo these are 
  682. accessed as global variables. If you do not wish to use this feature, define ArgCName to be 
  683. argc, ArgVName to be argv, and MainName (normally "PASCAL_MAIN") to be blank. This 
  684. will work if argc and argv are never accessed outside of your main program. BUGS P2c was 
  685. designed with the idea that clean, readable output in most cases is worth more than guaranteed 
  686. correct output in extreme cases. P2c is not a compiler! However, ideally the "extreme" cases 
  687. would include only those which never arise in real life. Thus if p2c actually generates incorrect 
  688. code I will consider it a bug, but I will not apologize for it. :-) Below are the major remaining 
  689. cases where this is known to occur.
  690.  
  691. Certain kinds of conformant array parameters (including multi-dimensional conformant arrays) 
  692. produce code that declares variable-length arrays in C. Only a few C compilers, such as the 
  693. GNU C compiler, support this language extension. Otherwise some hand re-coding will be 
  694. required.
  695.  
  696. HP Pascal try - recover structures are translated into calls to TRY and RECOVER macros, 
  697. which are defined to simulate the construct using setjmp and longjmp. If this emulation does not 
  698. work, define the symbol FAKE_TRY to cause these macros to become "inert." (In cases where 
  699. the error is detected by code physically within the body of the try statement, a C goto to the 
  700. recover section is always generated.) Also, local file variables in scopes which are destroyed by 
  701. an escape are not closed.
  702.  
  703. Non-local GOTO's and try - recover statements are each implemented, but may conflict if both 
  704. are used at once. Non-local GOTO's are fairly careful about closing files that go out of scope but 
  705. may fail to do so in the presence of recursion.
  706.  
  707. Arrays containing files are not initialized to NULL as other files are. In some cases, such as file 
  708. variables allocated by NEW, the file is initialized but not automatically closed by DISPOSE.
  709.  
  710. LINK variables allowing sub-procedures access to their parents' variables are occasionally 
  711. omitted by mistake, if the access is too indirect for p2c to notice. If this happens, you can add an 
  712. explicit reference to a parent variable in the sub-procedure. A statement of the form "a:=a" will 
  713. count as a reference but then be optimized away by p2c.
  714.  
  715. Many aspects of Modula-2 are translated only superficially. For example, the type-compatibility 
  716. properties of the WORD and ARRAY OF WORD types are only roughly modelled, as are the 
  717. scope rules concerning modules.
  718.  
  719. Parts of VAX Pascal are still untreated. In particular, the [UNSAFE] attribute and a few others 
  720. are not fully supported, nor are the semantics of the OPEN procedure.
  721.  
  722. Turbo and VAX Pascal's double, quadruple, and extended real types all translate to the C double 
  723. type. Turbo's computational type is not supported at all.
  724.  
  725. Because Pascal strings (with length bytes) are translated into C strings (with null terminators), 
  726. certain Pascal string tricks will not work in the translated code. For example the assignment 
  727. s[0]:=chr(x) is translated to s[x]=0 on the assumption that the string is being shortened. If x is 
  728. actually greater than the current length, but not of a recognizable form like ord(s[0])+n, then the 
  729. generated code will not work. In VAX Pascal this corresponds to performing arithmetic on the 
  730. LENGTH field of a varying-length string.
  731.  
  732. Turbo Pascal's automatic clipping of strings is not supported. In Turbo, if a ten character string 
  733. is assigned to a string[8] variable, the last two characters are silently removed. The code 
  734. produced by p2c generally will overrun the target string instead! The StringTruncLimit 
  735. parameter (80 by default if Language = Turbo ) specifies a string size which should be 
  736. considered "short"; assignments of potentially-long strings to short string variables will cause a 
  737. warning but will not automatically truncate. The cure is to use copy in the Pascal source to 
  738. truncate the strings explicitly. 
  739.  
  740. FILES
  741.  
  742. file.xxx    Pascal source files r 
  743. file.c    resulting C source file 
  744. module.h    resulting C header file
  745. p2c Preferences    local configuration file r 
  746. p2c Preferences    in the System preferences folder: system-wide configuration file r 
  747. system.imp    declarations for predefined functions
  748. system.m2    analogous declarations for Modula-2
  749. *.imp    interface text for standard modules; (mpw.imp for MPW)
  750. p2c.h    header file for translated programs
  751. libp2c.a    run-time library
  752.  
  753. AUTHOR 
  754.     Dave Gillespie, daveg@csvax.cs.caltech.edu.
  755.     Günther Sawitzki, gs@statlab.uni-heidelberg.de
  756.  
  757. Many thanks to William Bader, Steven Levi, Rick Koshi, Eric Raymond, Magne Haveraaen, 
  758. Dirk Grunwald, David Barto, Paul Fisher, Tom Schneider, and others whose suggestions and 
  759. bug reports have helped improve p2c in countless ways.
  760.  
  761. The original Unix version of p2c can be found on csvax.cs.caltech.edu.
  762.  
  763.